home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / lang / c++-part2 / 10283 < prev    next >
Encoding:
Text File  |  1996-08-05  |  980 b   |  40 lines

  1. Path: inforamp.net!ts9-03
  2. From: rmorin@inforamp.net (Randy Charles Morin)
  3. Newsgroups: comp.lang.c++
  4. Subject: Re: Save whole structures and reloading
  5. Date: Thu, 07 Mar 96 06:10:49 GMT
  6. Organization: MiddleWorld SoftWare
  7. Message-ID: <4hlul3$6jg@sam.inforamp.net>
  8. References: <4hinsi$34@ornews.intel.com>
  9. NNTP-Posting-Host: ts9-03.tor.inforamp.net
  10. X-Newsreader: News Xpress Version 1.0 Beta #4
  11.  
  12. In article <4hinsi$34@ornews.intel.com>,
  13.    ivan_m_hendricks@ccm2.hf.intel.com (Ivan Hendricks) wrote:
  14. >Is there a way to save a struct or class so that when I reread it from
  15. >a file, it will be in the same member variable/types that it came out
  16. >of?  Can someone please give me an example.
  17.  
  18. What you want is a persistent object?  Examples:
  19.  
  20. const char filename[]="C:\\HELLO.DAT"
  21. class myclass
  22. {
  23.     int a,b;
  24. public:
  25.     myclass()
  26.     {
  27.         ifpstream is(filename);
  28.         is >> a >> b;
  29.     };
  30.     ~myclass()
  31.     {
  32.         ofpstream os(filename);
  33.         os << a << b;
  34.     };
  35. };
  36.  
  37. Of course, this is a simplistic example.
  38.  
  39. Agrivar
  40.